home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 386 / algrtest / pushzero.s < prev    next >
Text File  |  1985-11-19  |  7KB  |  167 lines

  1.  ; Program Name:  PUSHZERO.S
  2.  ;      Version:  1.003
  3.  
  4.  ; Assembly Instructions:
  5.  
  6.  ;    Assemble in AssemPro PC-relative mode and save with a TOS extension.
  7.  
  8.  ; Execution Instructions:
  9.  
  10.  ;    Execute from the desktop; or execute SPAWN.TTP, type PUSHZERO.TOS on
  11.  ; its command line and view this program's output in PUSHZERO.DAT.
  12.  
  13.  ; Program Function:
  14.  
  15.  ; For each of the three methods of pushing $0 onto the stack discussed in
  16.  ; chapter two, calculates the memory occupied by each instruction, and
  17.  ; calculates the execution time in milliseconds required for 50,000
  18.  ; executions of each.
  19.  
  20.  ; Then, in order to emphasize the comparison for a more practical type of
  21.  ; application, the one statement in the third algorithm that needs be 
  22.  ; executed only once, before the execution of the loop, is placed outside
  23.  ; of the loop, and the time for 50,000 executions of the third method is
  24.  ; repeated.
  25.  
  26. calculate_program_size:
  27.  lea        -$102(pc), a1       ; Fetch basepage start address.
  28.  lea        program_end, a0     ; Fetch program end address.
  29.  adda.l     #100512, a0         ; Attach large stack space to end of program.
  30.  
  31.  ; NOTE: The above method of declaring stack space at the end of this program is
  32.  ;       preferable to that which I have been using because, if a label were
  33.  ;       used to declare the stack in the bss section, then the label used
  34.  ;       to mark the end of the program would be too far to permit the program
  35.  ;       to be assembled in AssemPro's PC-relative mode.
  36.  
  37.  movea.l    a0, a7              ; Point A7 to this program's stack.
  38.  trap       #6                  ; Return unused memory to op system.
  39.  
  40. print_heading:
  41.  lea        heading, a0
  42.  bsr        print_string
  43.  
  44. push_method_1:
  45.  lea        header_1, a0
  46.  bsr        print_string
  47.  move.l     #49999, d7          ; D7 is counter for the push loop.
  48.  trap       #3                  ; Fetch start time.
  49.  move.l     d0, d3              ; Save start_time in D3.          
  50. push_1_loop:                    ; Marks start of instruction in the loop.
  51.  clr.w      -(sp)               ; Instruction in the loop.
  52. memory_1:                       ; Marks end of instruction in the loop.
  53.  dbra       d7, push_1_loop     ; Loop 50000 times.
  54.  trap       #3                  ; Fetch end time.
  55.  sub.l      d3, d0              ; Subtract start time from end time.
  56.  trap       #10                 ; Convert to decimal milliseconds and print.
  57.  adda.l     #100000, sp         ; Reset stack pointer to top of stack.
  58.  
  59. print_method_1_requisite_memory:
  60.  lea        header_5, a0        ; Print requisite memory header.
  61.  bsr        print_string
  62.  lea        memory_1, a0        ; Calculate number of bytes occupied by the
  63.  lea        push_1_loop, a1     ; instruction in the loop.
  64.  suba.l     a1, a0
  65.  bsr        print_requisite_memory
  66.                        
  67. push_method_2:
  68.  lea        header_2, a0
  69.  bsr        print_string
  70.  move.l     #49999, d7          ; D7 is counter for the push loop.
  71.  trap       #3                  ; Fetch start time.
  72.  move.l     d0, d3              ; Save start_time in D3.
  73. push_2_loop:                    ; Marks start of instruction in the loop.   
  74.  move.w     #0, -(sp)           ; Instruction in the loop.
  75. memory_2:                       ; Marks end of instruction in the loop.
  76.  dbra       d7, push_2_loop     ; Loop 50000 times.
  77.  trap       #3                  ; Fetch end time.
  78.  sub.l      d3, d0              ; Subtract start time from end time.
  79.  trap       #10                 ; Convert to decimal milliseconds and print.
  80.  adda.l     #100000, sp         ; Reset stack pointer to top of stack.
  81.  
  82. print_method_2_requisite_memory:
  83.  lea        header_6, a0        ; Print requisite memory header.
  84.  bsr.s      print_string
  85.  lea        memory_2, a0        ; Calculate number of bytes occupied by the
  86.  lea        push_2_loop, a1     ; instruction in the loop.
  87.  suba.l     a1, a0
  88.  bsr.s      print_requisite_memory
  89.  
  90. push_method_3:
  91.  lea        header_3, a0
  92.  bsr.s      print_string
  93.  move.l     #49999, d7          ; D7 is counter for the push loop.
  94.  trap       #3                  ; Fetch start time.
  95.  move.l     d0, d3              ; Save start_time in D3.
  96. push_3_loop:                    ; Marks start of instructions in the loop.
  97.  moveq      #0, d0              ; There are two instructions in the loop.
  98.  move.w     d0, -(sp)           ; 
  99. memory_3:                       ; Marks end of instructions in the loop.
  100.  dbra       d7, push_3_loop     ; Loop 50000 times.
  101.  trap       #3                  ; Fetch end time.
  102.  sub.l      d3, d0              ; Subtract start time from end time.
  103.  trap       #10                 ; Convert to decimal milliseconds and print.
  104.  adda.l     #100000, sp         ; Reset stack pointer to top of stack.
  105.  
  106. print_method_3_requisite_memory:
  107.  lea        header_7, a0        ; Print requisite memory header.
  108.  bsr.s      print_string
  109.  lea        memory_3, a0        ; Calculate number of bytes occupied by the
  110.  lea        push_3_loop, a1     ; instructions in the loop.
  111.  suba.l     a1, a0
  112.  bsr.s      print_requisite_memory
  113.  
  114. modified_push_method_3:
  115.  lea        header_4, a0
  116.  bsr.s      print_string
  117.  move.l     #49999, d7          ; D7 is counter for the push loop.
  118.  trap       #3                  ; Fetch start time.
  119.  move.l     d0, d3              ; Save start_time in D3.
  120.  moveq      #0, d0              ; Prestore $0 in D0.
  121. push_4_loop:
  122.  move.w     d0, -(sp)           ; Contents of D0 onto the stack.
  123.  dbra       d7, push_4_loop     ; Loop 50000 times.
  124.  trap       #3                  ; Fetch end time.
  125.  sub.l      d3, d0              ; Subtract start time from end time.
  126.  trap       #10                 ; Convert to decimal milliseconds and print.
  127.  adda.l     #100000, sp         ; Reset stack pointer to top of stack.
  128.  
  129. terminate:
  130.  trap       #8
  131.  
  132.  ;
  133.  ; SUBROUTINES
  134.  ;
  135.  
  136. print_requisite_memory:
  137.  move.l     a0, d1
  138.  trap       #4
  139.  bsr.s      print_string
  140.  lea        header_8, a0
  141.  bsr.s      print_string
  142.  rts
  143.  
  144. print_string:                   ; Expects address of string to be in A0.
  145.  move.l     a0, -(sp)           ; Push address of string onto stack.
  146.  move.w     #9, -(sp)           ; Function = c_conws = GEMDOS $9.
  147.  trap       #1                  ; GEMDOS call
  148.  addq.l     #6, sp              ; Reset stack pointer to top of stack.
  149.  rts
  150.  
  151.  data
  152. heading:         dc.b $D,$A,"PUSHZERO Execution Results",$D,$A,$D,$A,0
  153. header_1:        dc.b "   Elapsed time for clr.w  -(sp):     ",0
  154. header_2:        dc.b "   Elapsed time for move.w #0, -(sp): ",0
  155. header_3:        dc.b "   Elapsed time for moveq  #0, d0",$D,$A
  156.                  dc.b "                    move.w d0, -(sp): ",0
  157. header_4:        dc.b "   Time for only    move.w d0, -(sp): ",0
  158. header_5:        dc.b "   Requisite memory:                     ",0
  159. header_6:        dc.b "   Requisite memory:                     ",0
  160. header_7:        dc.b "   Requisite memory:                     ",0
  161. header_8:        dc.b "  bytes",$D,$A,$D,$A,0
  162.  bss
  163.  align                       
  164. program_end:     ds.l      0 
  165.  end
  166.  
  167.